fix: scope CM6 Tidy keymap per file state (#4093)#4097
Conversation
createNewFileState mutated a module-scoped extraKeymaps array by pushing a Shift-Mod-F binding that closed over the current file's mode. Because the array was shared across every file's state, later-created files accumulated multiple tidy handlers — Cmd+Shift+F on a CSS/HTML file ran prettier with the JS parser first, either throwing or mangling output. Move the tidy binding into a per-state local array and return true from the handler so CM6 consumes the shortcut. Add a regression test that creates JS/CSS/HTML states in order and verifies each tidies with its own mode.
|
@dimssu Thank you for the PR. Please share the video preview for the fix |
|
Hi @dimssu, I think we can't raise a PR for an issue with the "Awaiting Maintainer Approval" label. I think you should first let a maintainer approve the issue, only then raise a PR. Thanks! |
|
HI @dimssu just checking in, are you still working on this? Would you be able to share video preview to make this easier to review? |
|
@ksen0 @yugalkaushik — yes, still on this. I've added the fix video to the PR description above (under Fix video). It walks through |
khanniie
left a comment
There was a problem hiding this comment.
hi, thank you so much for identifying the issue and submitting a fix! it looks great and I really appreciate all the work you put into this! apologies in the delay in looking at this
Issue:
Fixes #4093
In the CM6 editor (
develop-codemirror-v6), the Tidy shortcut (Cmd/Ctrl+Shift+F) works on the first file but misbehaves on subsequent files — sometimes nothing happens, sometimes the file is reformatted as "one big block."Root cause:
createNewFileStateinclient/modules/IDE/components/Editor/stateUtils.jspushed a Shift-Mod-F binding into a module-scopedextraKeymapsarray, closing over the current file's mode. Because later-created file states snapshot that shared array, files created after the first end up with multiple tidy handlers (one per previously-initialized file's mode). On a CSS file, the JS-mode tidy runs first → prettier's babel parser throws on CSS, or (for files it can parse) mangles the content before the correct-mode tidy ever runs.The Edit → Tidy Code menu click path was unaffected because it computes the mode from
file.nameat call time.Changes:
stateUtils.js: stop mutating the module-levelextraKeymaps. Build the tidy binding as a per-state local array (fileTidyKeymap) and include it in the state's keymaps. Handler now returnstrueso CM6 consumes the shortcut.stateUtils.test.js: new regression test. Creates JS, CSS, and HTML file states in order, dispatchesShift-Ctrl-FviarunScopeHandlers, and asserts each file is tidied with its own mode. Test fails on the previous code (prettier throws parsing CSS as JS) and passes on the fix.###Fix video:
Screen.Recording.2026-05-12.at.3.30.40.AM.mp4
Uploading Screen Recording 2026-05-12 at 3.30.40 AM.mp4…
Testing:
Manually verified that pressing
Cmd+Shift+Fnow tidies correctly insketch.js,style.css, andindex.htmlregardless of which file is opened first.I have verified that this pull request:
npm run lint)npm run test— Editor suite; 9/9 pass)npm run typecheck)